import java.util.ArrayList;

public class Robot {
	private int _id;
	private ArrayList<Integer> _actions;
	private double _score;

	public Robot(int id, ArrayList<Integer> actions, double score) {
		set_id(id);
		set_actions(actions);
		set_score(score);
	}

	public Robot(int id, ArrayList<Integer> actions) {
		this(id, actions, 0);
	}

	public Robot(int id) {
		this(id, new ArrayList<Integer>());
	}

	public void set_id(int _id) {
		this._id = _id;
	}

	public int get_id() {
		return _id;
	}

	public void set_actions(ArrayList<Integer> _actions) {
		this._actions = _actions;
	}

	public ArrayList<Integer> get_actions() {
		return _actions;
	}

	public void set_score(double _score) {
		this._score = _score;
	}

	public double get_score() {
		return _score;
	}

	public String robotToSmall() {
		ActionServices as = new ActionServices();
		// Carga inicial del codigo
		String code = "//--------------\n// GunTactyx API\n//--------------\n\n#include \"core\"\n#include \"math\"\n#include \"bots\"\n\n//-------------------\n// internal constants\n//-------------------\n\nnew const float:PI = 3.1415\nnew const float:ARENA_SIDE = 131.5\nnew const FRIEND_WARRIOR = ITEM_FRIEND|ITEM_WARRIOR\nnew const FRIEND_GUN = ITEM_FRIEND|ITEM_GUN\nnew const ENEMY_WARRIOR = ITEM_ENEMY|ITEM_WARRIOR\nnew const ENEMY_GUN = ITEM_ENEMY|ITEM_GUN\n\n//--------------------------\n// internal global variables\n//--------------------------\n\nnew float:STRATEGY = 0.0\nnew float:TACTIC = 0.0\nnew float:PIS = 0.0\nnew float:PIQ = 0.0\nnew float:PIT = 0.0\nnew float:PID = 0.0\nnew float:ARENA_SIDED = 0.0\nnew float:ARENA_SIDEQ = 0.0\nnew float:lasttime = 0.0\nnew scanned = 0\nnew started = 1\n\n//------------------------\n// action global variables\n//------------------------\n\n//<$global$>\n\n//-----------\n// procedures\n//-----------\n\nfloat:getLocationYaw(float:px,float:py,&float:yaw) {\n\tnew float:dist = 0.0\n\tnew float:x\n\tnew float:y\n\tnew float:dx\n\tnew float:dy\n\tnew float:ryaw\n\t//new float:ryawp\n\n\tgetLocation(x, y)\n\n\tdx = (px - x)\n\tdy = (py - y)\n\n\t// calculate rotate from 0.0rad to target\n\n\tif(dx >= 0.0) {\n\t\tif(dy == 0.0) {\n\t\t\tyaw = 0.0\n\t\t\tdist = dx\n\t\t} else if(dx == 0.0) {\n\t\t\tif(dy > 0) yaw = PID\n\t\t\telse yaw = -PID\n\t\t\tdist = dy\n\t\t} else {\n\t\t\tyaw = atan(dy/dx)\n\t\t\tdist = abs(y/sin(yaw))\n\t\t}\n\t} else {\n\t\tif(dy == 0.0) {\n\t\t\t//yaw = (getDirection()+getTorsoYaw()+getHeadYaw())\n\t\t\t//if(getDirection() > 0.0) yaw = -PI\n\t\t\t//else yaw = PI\n\t\t\tyaw = 0.0\n\t\t\tdist = -dx\n\t\t} else {\n\t\t\tyaw = atan(dx/dy)\n\t\t\tdist = abs(x/sin(yaw))\n\t\t\tif(dy > 0.0) yaw = (PID-yaw)\n\t\t\telse yaw = -(PID+yaw)\n\t\t}\n\t}\n\n\t// calculate rotate from robot point to target\n\n\tryaw = getDirection()+getTorsoYaw()+getHeadYaw()\n\tyaw -= ryaw\n\n\treturn dist\n}\n\nfighter() {\n\tnew item = ITEM_WARRIOR\n\tnew float:dist = 0.0\n\tnew float:yaw\n\tnew float:pitch\n\tnew float:x\n\tnew float:y\n\tnew float:z\n\tnew touched\n\tnew sound\n\n";
		// Se agregan las acciones
		for (int strategy = 0; strategy < Main.NR_STRATEGIES; strategy++) {
			code += "\twhile(STRATEGY == " + strategy + ".0) {\n";
			for (int tactic = 0; tactic < Main.NR_TACTICS; tactic++) {
				code += "\t\twhile((STRATEGY == " + strategy
						+ ".0) && (TACTIC == " + tactic + ".0)) {\n";
				for (int i = 0; i < get_actions().size(); i++) {
					code += as.GetAction(get_actions().get(i).intValue())
							.actionToSmall();
				}
				code += "\t\t}\n";
			}
			code += "\t}\n";
		}
		// Se termina de generar el codigo
		code += "\n\n}\n\n\nmain() {\n\n\t//--- start time\n\n\tlasttime = getTime()\n\n\t//--- PI calculations\n\n\tPIS = (PI/6)\n\tPIQ = (PI/4)\n\tPIT = (PI/3)\n\tPID = (PI/2)\n\n\t//--- arena side size\n\n\tARENA_SIDED = ARENA_SIDE / 2\n\tARENA_SIDEQ = ARENA_SIDE / 4\n\n\t//--- actions startup\n\t\t\n//<$startup$>\n\n\t//--- game play\n\n\t fighter()\n}\n\n";
		return code;
	}
}